package my.interview;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 开发一个方法，接受二维数组input作为入参，返回国家名称字符串数组，按奖牌榜第一到第N进行排序。
 * 入参参考；String[][] input =
 * {{"CHINA","32","28","34"},
 * {"England","12","34","22"},
 * {"France","23","33","2"},
 * {"Japan","12","34","25"},
 * {"Rusia","23","43","0"}};
 * 每一个数组表示 国家/金牌数/银牌数/铜牌数。
 * 方法参考：
 * String[] sort(String[][] input) {
 * //TODO
 * }
 */
public class Test2 {

    public static void main(String[] args) {
        String[][] strings = new String[][]{{"CHINA", "32", "28", "34"},
                {"England", "12", "34", "22"},
                {"France", "23", "33", "2"},
                {"Japan", "12", "34", "25"},
                {"Rusia", "23", "43", "0"}};
        String[] result = getResult(strings);
        System.out.println(Arrays.asList(result));
    }

    private static String[] getResult(String[][] strings) {
        List<String[]> collect = Arrays.stream(strings).sorted(new Comparator<String[]>() {
            @Override
            public int compare(String[] o1, String[] o2) {
                int x1 = Integer.parseInt(o2[1]) - Integer.parseInt(o1[1]);
                int x2 = Integer.parseInt(o2[2]) - Integer.parseInt(o1[2]);
                int x3 = Integer.parseInt(o2[3]) - Integer.parseInt(o1[3]);
                // return x1 == 0 ? (x2 == 0 ? x3) : x1;
                // return Integer.parseInt(o2[1]) - Integer.parseInt(o1[1]) == 0 ? (Integer.parseInt(o2[1]) - Integer.parseInt(o1[1]) == 0 ? : Integer.parseInt(o2[3]) - Integer.parseInt(o1[3]));
                return 1;
            }
        }).collect(Collectors.toList());

        String[] result = new String[strings.length];
        for (int i = 0; i < collect.size(); i++) {
            result[i] = collect.get(i)[0];
        }
        return result;
    }
}
